package com.github.thinwonton.showcase.springboot.security.security.support;

import com.github.thinwonton.showcase.springboot.security.po.SystemUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录成功后的处理器
 *
 * @author hugo
 * @date 2018/7/13
 */
public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        //获取认证成功后的用户信息
        SystemUser systemUser = (SystemUser) authentication.getPrincipal();
        System.out.println("用户[" + systemUser.getUserName() + "]登录");
        super.onAuthenticationSuccess(request, response, authentication);
    }
}
